/*
 * VCRUserbitsAdapter.java
 *
 * Created on January 6, 2006, 3:13 PM
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package org.mbari.vcr;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.mbari.util.IObserver;
import org.mbari.util.ObservableSupport;

/**
 *
 * @author brian
 */
public class VCRUserbitsAdapter implements IVCRUserbits {
    
    /**
	 * @uml.property  name="os"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
    private final ObservableSupport os = new ObservableSupport();
    private static final Logger log = LoggerFactory.getLogger(VCRUserbitsAdapter.class);    
    /**
	 * @uml.property  name="userbits" multiplicity="(0 -1)" dimension="1"
	 */
    private byte[] userbits = new byte[]{1, 2, 3, 4};
    
    /** Creates a new instance of VCRUserbitsAdapter */
    public VCRUserbitsAdapter() {
    }

    /**
	 * @return  the userbits
	 * @uml.property  name="userbits"
	 */
    public byte[] getUserbits() {
        return userbits;
    }
    
    /**
	 * @param userbits  the userbits to set
	 * @uml.property  name="userbits"
	 */
    public void setUserbits(byte[] userbits) {
        this.userbits = userbits;
        notifyObservers();
    }

    public void addObserver(IObserver observer) {
        os.add(observer);
    }

    public void removeAllObservers() {
        os.clear();
    }

    public void removeObserver(IObserver observer) {
        os.remove(observer);
    }
    
    /** Notifies all the observers of a chage of state */
    protected void notifyObservers() {
        if (log.isDebugEnabled()) {
            StringBuffer b = new StringBuffer("Notification of new Userbits: [");
            for (int i = 0; i < userbits.length; i++) {
                b.append(userbits[i]);
                if (i < userbits.length - 1) {
                    b.append(", ");
                }
            }
            b.append("]");
            log.debug(b.toString());
        }
        os.notify(this, null);
    }
    
}
